/*
 * @Title: 用户store
 * @Description: 描述
 * @FilePath: /vue3-admin-naive-starter/src/stores/user.ts
 */

import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useLoginApi } from '@/api/login'

import { sideRoutes } from '@/router/route'

export type LoginUserInfo = {}

export const useUserStore = defineStore('user', () => {
  // 设置用户信息
  const userInfo = ref<LoginUserInfo>({
    account: '',
    empId: '',
    empName: '',
    mobile: '',
    org: null,
    tenant: null
  })

  /**
   * 用户信息操作
   */
  const getUserInfo = async () => {
    const res: LoginUserInfo = await useLoginApi().getUserInfo()
    const { data } = res
    userInfo.value = data
    return userInfo.value
  }
  /**
   * ======================用户菜单相关============================
   */
  // const menuRaw = useStorage<UserAuthMenuRawItem[]>('menuRaw', []);
  const menuTree = ref<any[]>([...sideRoutes])

  return {
    userInfo,
    getUserInfo,
    menuTree
  }
})
